﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DepartmentWork.Migrator
{
    class Program
    {
        static void Main(string[] args)
        {

            Console.Write("是否希望自动创建数据库：[Y/N]");
            string result = Console.ReadLine();
            if (result.ToUpper().Trim() == "Y")
            {
                DepartmentWorkDbContext db = new DepartmentWorkDbContext();
                try
                {
                    db.Database.Create();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                Console.WriteLine("数据库创建完毕！");
                Console.WriteLine("准备初始化数据库，请稍后.....");
                try
                {
                    DepartmentWorkDbInitializer init = new DepartmentWorkDbInitializer();
                    init.InitializeDatabase(db);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                Console.WriteLine("数据库初始化完毕！");

                try
                {
                    Console.WriteLine("开始配置数据库，请稍后.....");
                    db.Database.ExecuteSqlCommand(
    "ALTER TABLE TEAMSPACEs ADD CONSTRAINT TEAMSPACEs_NAME_UNIQUE UNIQUE(TEAMSPACE_NAME)");
                    Console.WriteLine("数据库配置完毕！");
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

            }
            else
            {
                Console.WriteLine("程序结束...");
            }

            Console.ReadLine();
        }
    }
}
